package org.example.node;

/**
 * @author liyishan
 * @date 2024/9/9 09:17
 * @apiNote
 */

public class Test02181MergeNodes {
    public ListNode mergeNodes(ListNode head) {
        ListNode dummy = new ListNode();
        ListNode tail = dummy;
        ListNode cur = head.next;
        int total = 0;
        while(cur != null){
            if(cur.val == 0){
                ListNode node = new ListNode(total);
                tail.next = node;
                tail = tail.next;
                total = 0;
            }else{
                total += cur.val;
            }
            cur = cur.next;
        }
        return dummy.next;
    }
}
